package com.billdowney.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.billdowney.annotation.AuthRoleAllowed;
import com.billdowney.annotation.SystemLogInfo;
import com.billdowney.controller.BaseController;
import com.billdowney.service.interfaces.system.SystemDirectoryService;
import com.billdowney.util.auth.AuthRoleConst;
import com.billdowney.util.log.SystemLogHandleType;
import com.billdowney.util.return_type.ReturnData;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import com.billdowney.entity.system.SystemDirectory;
import com.billdowney.entity.system.SystemDirectoryType;;

/**
 * @Description: 系统目录控制器
 * @author 超级小富翁 - BillDowney
 * @date 2018年9月2日 上午10:54:34
 */
@RestController
@RequestMapping(value = "/systemDirectory", method = { RequestMethod.POST })
@Api(tags = "系统目录控制器")
public class SystemDirectoryController extends BaseController {

	@Autowired
	private SystemDirectoryService directoryService;

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/queryDirectoryList")
	@ApiOperation(value = "获取目录列表", notes = "通过父级id来获取子级目录；id：为空的时候则查询全部数据；type：目录类别", response = SystemDirectory.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "parentId", value = "父级id，为空的时候则查询全部数据"),
			@ApiImplicitParam(name = "type", value = "目录类别", required = true) })
	public Object queryDirectoryList(String parentId, SystemDirectoryType type) throws Exception {
		return new ReturnData(directoryService.queryList(parentId, type));
	}

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/delDirectory")
	@SystemLogInfo(value = "删除目录：{id}", handleType = SystemLogHandleType.delete)
	@ApiOperation(value = "删除目录", response = Boolean.class)
	@ApiImplicitParam(name = "id", value = "目录id")
	public Object delDirectory(String id) throws Exception {
		return new ReturnData(directoryService.delSystemDirectory(id));
	}

	@AuthRoleAllowed(AuthRoleConst.ROLE_ADMIN)
	@RequestMapping(value = "/saveOrUpdateDirectory")
	@SystemLogInfo(value = "保存或更新目录：{id}", handleType = SystemLogHandleType.saveOrUpdate)
	@ApiOperation(value = "保存或更新目录列表", response = SystemDirectory.class)
	@ApiImplicitParams({ @ApiImplicitParam(name = "name"), @ApiImplicitParam(name = "id"),
			@ApiImplicitParam(name = "type", value = "目录类别", required = true),
			@ApiImplicitParam(name = "parentId", value = "父级id") })
	public Object saveOrUpdateDirectory(String name, String id, @RequestParam SystemDirectoryType type, String parentId)
			throws Exception {
		return new ReturnData(directoryService.saveOrUpdateSystemDirectory(name, id, type, parentId));
	}

}
